﻿//JSON date time functions -------------------
function JSONDate(dateStr) {
    var month = new Array();
    month[1] = "Jan";
    month[2] = "Feb";
    month[3] = "Mar";
    month[4] = "Apr";
    month[5] = "May";
    month[6] = "Jun";
    month[7] = "Jul";
    month[8] = "Aug";
    month[9] = "Sep";
    month[10] = "Oct";
    month[11] = "Nov";
    month[12] = "Dec";
    var m, day;
    var jsonDate = dateStr;
    var d = new Date(parseInt(jsonDate.substr(6)));
    m = d.getMonth() + 1;
    if (m < 10)
        m = '0' + m;
    if (d.getDate() < 10)
        day = '0' + d.getDate();
    else
        day = d.getDate();
    return (day + '  ' + month[m] + ' ' + d.getFullYear());
}

function JSONDateToNormal(dateStr) {
    var m, day;
    var jsonDate = dateStr;
    var d = new Date(parseInt(jsonDate.substr(6)));
    m = d.getMonth() + 1;
    if (m < 10)
        m = '0' + m;
    if (d.getDate() < 10)
        day = '0' + d.getDate();
    else
        day = d.getDate();
    return (m + '/' + day + '/' + d.getFullYear());
}

function JSONDateWithTime(dateStr) {
    var jsonDate = dateStr;
    var d = new Date(parseInt(jsonDate.substr(6)));
    var m, day;
    m = d.getMonth() + 1;
    if (m < 10)
        m = '0' + m
    if (d.getDate() < 10)
        day = '0' + d.getDate()
    else
        day = d.getDate();
    var formattedDate = day + "." + m + "." + d.getFullYear();
    var hours = (d.getHours() < 10) ? "0" + d.getHours() : d.getHours();
    var minutes = (d.getMinutes() < 10) ? "0" + d.getMinutes() : d.getMinutes();
    var formattedTime = hours + ":" + minutes;
    formattedDate = formattedDate + " at " + formattedTime;
    return formattedDate;
}

function JSONTime(dateStr) {
    var jsonDate = dateStr;
    var d = new Date(parseInt(jsonDate.substr(6)));
    var hours = (d.getHours() < 10) ? "0" + d.getHours() : d.getHours();
    var minutes = (d.getMinutes() < 10) ? "0" + d.getMinutes() : d.getMinutes();
    var formattedTime = hours + ":" + minutes;
    return formattedTime;
}

//JSON date time functions -------------------






//Get query string function

function querySt(key) {
    var url = window.location.href;
    var keysValues = url.split(/[\?&]+/);
    for (var i = 0; i < keysValues.length; i++) {
        var keyValue = keysValues[i].split("=");
        if (keyValue[0] == key) {
            return keyValue[1];
        }
    }
    return "";
}

//Get query string function

//Ajax calls function

function ajaxCall(execPlace, isAsync, data, onSuccess, onError) {
    $.ajax({
        type: 'POST',
        async: isAsync,
        contentType: 'application/json; charset=utf-8',
        url: execPlace,
        dataType: 'json',
        data: data,
        success: onSuccess,
        error: onError
    });  
}
//Ajax calls function





//Create uploader function

function createUploader(elem, act, param, allowedEx, uploadBtnText, submitFunc) {
    var uploadedItem = new qq.FileUploader({
        element: elem,
        action: act,
        params: param,
        allowedExtensions: allowedEx,
        autoUpload: false,
        progressBar: 'qq-progress-bar',
        minSizeLimit: 0,
        uploadButtonText: uploadBtnText,
        multiple: false,
        debug: true,
        onSubmit: submitFunc
    });
    
    return uploadedItem;
}

//Create uploader function





